package ExtendDemo.demo14;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class ServerDemo {
    public static void main(String[] args)  throws IOException {
        ServerSocket ss = new ServerSocket(10004);
        ThreadPoolExecutor pool=new ThreadPoolExecutor(
                3,//核心线程数量
                10,//线程总数量
                60,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(5),//阻塞队列
                Executors.defaultThreadFactory(),//创建线程的方式
                new ThreadPoolExecutor.AbortPolicy()//拒绝策略
        );
        while (true) {
            Socket s = ss.accept();
            ThreadServer threadServer=new ThreadServer(s);
//            new Thread(threadServer).start();
            pool.submit(threadServer);

        }

    }
}
